package com.linyaonan.leetcode.easy._590;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Lin
 * @date: 2020/1/3
 */
public class PostorderTree {
    List<Integer> list = new ArrayList<>();
    public List<Integer> postorder(Node root) {
        nfs(root);
        return list;
    }

    private void nfs(Node node) {
        if (node != null) {
            List<Node> children = node.children;
            if (children != null) {
                for (Node child : children) {
                    nfs(child);
                }
            }
            list.add(node.val);
        }
    }
}
